//
//  RBDZVideoViewController.m
//  rubaoduanzi
//
//  Created by 李云飞 on 16/9/13.
//  Copyright © 2016年 liyunfei. All rights reserved.
//

#import "RBDZVideoViewController.h"
#import "RBDZButton.h"
#import <AFNetworking.h>
#import "RBDZVideoTableViewCell.h"
@interface RBDZVideoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation RBDZVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"儒豹视频";
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self addItem];
    [self loadData];
}
#pragma mark 请求数据
-(void)loadData{
    //创建数据管理者
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    NSString *url=@"http://mobileapi1.roboo.com/joke/videoSearch.do?q=&p=1&ps=15";
    //请求数据
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [responseObject writeToFile:@"/Users/liyunfei/Desktop/火影忍者/33.plist" atomically:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"网络错误");
    }];
    
    
    
}
#pragma mark 返回多少组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
#pragma mark 返回每组多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 20;
}
#pragma mark 返回每行的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID=@"Cell";
    RBDZVideoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell=[RBDZVideoTableViewCell VideoTableViewCell];
    }
    
    return cell;
}
#pragma mark 添加导航栏按钮
-(void)addItem{
    UIButton *buttonL=[UIButton buttonWithType:UIButtonTypeCustom];
    self.navigationItem.leftBarButtonItem=[RBDZButton barButtonItemWith:buttonL andTarget:self action:@selector(leftBtn) andImageName:@"nav_menu" andHightlightImage:nil];
    UIButton *buttonR=[UIButton buttonWithType:UIButtonTypeCustom];
    self.navigationItem.rightBarButtonItem=[RBDZButton barButtonItemWith:buttonR andTarget:self action:@selector(rightBtn) andImageName:@"nav_fb" andHightlightImage:@"nav_fb_pre"];
    
}
#pragma mark 导航栏左边按钮的监听事件
-(void)leftBtn{
    RBDZMEViewController *me=[[RBDZMEViewController alloc]init];
    me.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:me animated:YES];
}
#pragma mark 导航栏右边按钮的监听事件
-(void)rightBtn{
    //NSLog(@"%s",__func__);
    RBDZContributeViewController *contribute=[[RBDZContributeViewController alloc]init];
    [self.navigationController pushViewController:contribute animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
